﻿using MediatR;
using Traceability.App.Api.Read.Application.Command.Health;
using Traceability.App.Domain;
using Traceability.App.Domain.养殖基本信息表;
using Traceability.App.ErrorCode;
using Traceability.App.Intrastructure.Interface;

namespace Traceability.App.Api.Read.Application.Handler.Health
{
    public class HealthShowHandler : IRequestHandler<HealthShowCommand, ApiResult<List<HealthModel>>>
    {
        private readonly IBaseRepository<HealthModel> healthRepo;

        public HealthShowHandler(IBaseRepository<HealthModel> healthRepo)
        {
            this.healthRepo = healthRepo;
        }
        public Task<ApiResult<List<HealthModel>>> Handle(HealthShowCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<List<HealthModel>>();
            var m = healthRepo.GetAll().Where(x => x.ProduceBatch == request.ProduceBatch).ToList();
            res.Message = "保健显示成功";
            res.Code = ApiEnum.Ok;
            res.Data =m.ToList();
            return Task.FromResult(res);
        }
    }
}
